home *** CD-ROM | disk | FTP | other *** search
- .286p
- ifndef ??version
- publicdll macro name
- public name
- endm
- $comm macro name,dist,size,count
- comm dist name:BYTE:count*size
- endm
- else
- $comm macro name,dist,size,count
- comm dist name[size]:BYTE:count
- endm
- endif
- _TEXT segment byte public 'CODE'
- _TEXT ends
- DGROUP group _DATA,_BSS
- assume cs:_TEXT,ds:DGROUP
- _DATA segment word public 'DATA'
- d@ label byte
- d@w label word
- _DATA ends
- _BSS segment word public 'BSS'
- b@ label byte
- b@w label word
- _BSS ends
- _TEXT segment byte public 'CODE'
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- color_quant_prescan proc near
- push bp
- mov bp,sp
- sub sp,26
- push si
- push di
- ;
- ; color_quant_prescan (decompress_info_ptr cinfo, int num_rows,
- ; JSAMPIMAGE image_data, JSAMPARRAY workspace)
- ; {
- ; register JSAMPROW ptr0, ptr1, ptr2;
- ; register histptr histp;
- ; register int c0, c1, c2;
- ; int row;
- ; long col;
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx+38]
- mov dx,word ptr [bx+36]
- mov word ptr [bp-24],ax
- mov word ptr [bp-26],dx
- ;
- ; long width = cinfo->image_width;
- ;
- ;
- mov word ptr [bp-18],0
- jmp @1@242
- @1@50:
- ;
- ; for (row = 0; row < num_rows; row++) {
- ;
- mov ax,word ptr [bp-18]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; ptr0 = image_data[0][row];
- ;
- mov ax,word ptr [bp-18]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+2]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-6],ax
- mov word ptr [bp-8],dx
- ;
- ; ptr1 = image_data[1][row];
- ;
- mov ax,word ptr [bp-18]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+4]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-10],ax
- mov word ptr [bp-12],dx
- ;
- ; ptr2 = image_data[2][row];
- ;
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- mov word ptr [bp-20],ax
- mov word ptr [bp-22],dx
- jmp short @1@146
- @1@74:
- ;
- ; for (col = width; col > 0; col--) {
- ; /* get pixel value and index into the histogram */
- ;
- les bx,dword ptr [bp-4]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,2
- mov si,ax
- inc word ptr [bp-4]
- ;
- ; c0 = GETJSAMPLE(*ptr0++) >> Y_SHIFT;
- ;
- les bx,dword ptr [bp-8]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,3
- mov di,ax
- inc word ptr [bp-8]
- ;
- ; c1 = GETJSAMPLE(*ptr1++) >> C_SHIFT;
- ;
- les bx,dword ptr [bp-12]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,3
- mov cx,ax
- inc word ptr [bp-12]
- ;
- ; c2 = GETJSAMPLE(*ptr2++) >> C_SHIFT;
- ;
- mov ax,si
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,cx
- shl bx,1
- add dx,bx
- mov word ptr [bp-14],ax
- mov word ptr [bp-16],dx
- ;
- ; histp = & histogram[c0][c1][c2];
- ; /* increment, check for overflow and undo increment if so. */
- ; /* We assume unsigned representation here! */
- ;
- les bx,dword ptr [bp-16]
- inc word ptr es:[bx]
- mov ax,word ptr es:[bx]
- or ax,ax
- jne short @1@122
- ;
- ; if (++(*histp) == 0)
- ;
- dec word ptr es:[bx]
- @1@122:
- sub word ptr [bp-22],1
- sbb word ptr [bp-20],0
- @1@146:
- cmp word ptr [bp-20],0
- jg short @1@74
- jne short @1@218
- cmp word ptr [bp-22],0
- jbe @@0
- jmp @1@74
- @@0:
- @1@218:
- inc word ptr [bp-18]
- @1@242:
- mov ax,word ptr [bp-18]
- cmp ax,word ptr [bp+6]
- jge @@1
- jmp @1@50
- @@1:
- ;
- ; (*histp)--;
- ; }
- ; }
- ;
- pop di
- pop si
- leave
- ret
- color_quant_prescan endp
- ;
- ; LOCAL boxptr
- ;
- assume cs:_TEXT
- find_biggest_color_pop proc near
- push bp
- mov bp,sp
- sub sp,4
- push si
- push di
- ;
- ; find_biggest_color_pop (void)
- ; /* Find the splittable box with the largest color population */
- ; /* Returns NULL if no splittable boxes remain */
- ; {
- ; register boxptr boxp;
- ; register int i;
- ;
- mov word ptr [bp-2],0
- mov word ptr [bp-4],0
- ;
- ; register long max = 0;
- ;
- xor bx,bx
- ;
- ; boxptr which = NULL;
- ;
- ;
- xor di,di
- mov si,word ptr DGROUP:boxlist
- jmp short @2@242
- @2@50:
- ;
- ; for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
- ;
- mov ax,word ptr [si+14]
- mov dx,word ptr [si+12]
- cmp ax,word ptr [bp-2]
- jl short @2@218
- jg short @2@122
- cmp dx,word ptr [bp-4]
- jbe short @2@218
- @2@122:
- ;
- ; if (boxp->colorcount > max) {
- ;
- ;
- ; if (boxp->c0max > boxp->c0min || boxp->c1max > boxp->c1min ||
- ;
- mov ax,word ptr [si+2]
- cmp ax,word ptr [si]
- jg short @2@194
- mov ax,word ptr [si+6]
- cmp ax,word ptr [si+4]
- jg short @2@194
- mov ax,word ptr [si+10]
- cmp ax,word ptr [si+8]
- jle short @2@218
- @2@194:
- ;
- ; boxp->c2max > boxp->c2min) {
- ;
- mov bx,si
- ;
- ; which = boxp;
- ;
- mov ax,word ptr [si+14]
- mov dx,word ptr [si+12]
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- @2@218:
- inc di
- add si,16
- @2@242:
- cmp di,word ptr DGROUP:numboxes
- jl short @2@50
- ;
- ; max = boxp->colorcount;
- ; }
- ; }
- ; }
- ;
- mov ax,bx
- ;
- ; return which;
- ;
- pop di
- pop si
- leave
- ret
- find_biggest_color_pop endp
- ;
- ; LOCAL boxptr
- ;
- assume cs:_TEXT
- find_biggest_volume proc near
- push bp
- mov bp,sp
- sub sp,22
- push si
- push di
- ;
- ; find_biggest_volume (void)
- ; /* Find the splittable box with the largest (scaled) volume */
- ; /* Returns NULL if no splittable boxes remain */
- ; {
- ; register boxptr boxp;
- ; register int i;
- ;
- mov word ptr [bp-2],0
- mov word ptr [bp-4],0
- ;
- ; register INT32 max = 0;
- ; register INT32 norm, c0,c1,c2;
- ;
- mov word ptr [bp-22],0
- ;
- ; boxptr which = NULL;
- ;
- ; /* We use 2-norm rather than real volume here.
- ; * Some care is needed since the differences are expressed in
- ; * histogram-cell units; if HIST_Y_BITS != HIST_C_BITS, we have to
- ; * adjust the scaling to get the proper scaled-YCbCr-space distance.
- ; * This code won't work right if HIST_Y_BITS < HIST_C_BITS,
- ; * but that shouldn't ever be true.
- ; * Note norm > 0 iff box is splittable, so need not check separately.
- ; */
- ;
- ;
- xor di,di
- mov si,word ptr DGROUP:boxlist
- jmp @3@170
- @3@50:
- ;
- ; for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
- ;
- mov ax,word ptr [si+2]
- sub ax,word ptr [si]
- shl ax,1
- .386
- movsx eax, ax
- mov [bp-12], eax
- .286
- ;
- ; c0 = (boxp->c0max - boxp->c0min) * Y_SCALE;
- ;
- mov ax,word ptr [si+6]
- sub ax,word ptr [si+4]
- shl ax,1
- .386
- movsx ebx, ax
- mov [bp-16], ebx
- .286
- ;
- ; c1 = (boxp->c1max - boxp->c1min) << (HIST_Y_BITS-HIST_C_BITS);
- ;
- mov ax,word ptr [si+10]
- sub ax,word ptr [si+8]
- shl ax,1
- .386
- movsx ecx, ax
- mov [bp-20], ecx
- ;
- ; c2 = (boxp->c2max - boxp->c2min) << (HIST_Y_BITS-HIST_C_BITS);
- ;
- imul eax, eax
- imul ebx, ebx
- imul ecx, ecx
- add eax, ebx
- add eax, ecx
- mov [bp-8], eax
- .286
- ;
- ; norm = c0*c0 + c1*c1 + c2*c2;
- ;
- mov ax,word ptr [bp-6]
- mov dx,word ptr [bp-8]
- cmp ax,word ptr [bp-2]
- jl short @3@146
- jg short @3@122
- cmp dx,word ptr [bp-4]
- jbe short @3@146
- @3@122:
- ;
- ; if (norm > max) {
- ;
- mov word ptr [bp-22],si
- ;
- ; which = boxp;
- ;
- mov ax,word ptr [bp-6]
- mov dx,word ptr [bp-8]
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- @3@146:
- inc di
- add si,16
- @3@170:
- cmp di,word ptr DGROUP:numboxes
- jge @@2
- jmp @3@50
- @@2:
- ;
- ; max = norm;
- ; }
- ; }
- ;
- mov ax,word ptr [bp-22]
- ;
- ; return which;
- ;
- pop di
- pop si
- leave
- ret
- find_biggest_volume endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- update_box proc near
- push bp
- mov bp,sp
- sub sp,20
- push si
- push di
- ;
- ; update_box (boxptr boxp)
- ; /* Shrink the min/max bounds of a box to enclose only nonzero elements, */
- ; /* and recompute its population */
- ; {
- ; histptr histp;
- ; int c0,c1,c2;
- ; int c0min,c0max,c1min,c1max,c2min,c2max;
- ; long ccount;
- ;
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx]
- mov word ptr [bp-6],ax
- mov ax,word ptr [bx+2]
- mov word ptr [bp-8],ax
- ;
- ; c0min = boxp->c0min; c0max = boxp->c0max;
- ;
- mov ax,word ptr [bx+4]
- mov word ptr [bp-10],ax
- mov ax,word ptr [bx+6]
- mov word ptr [bp-12],ax
- ;
- ; c1min = boxp->c1min; c1max = boxp->c1max;
- ;
- mov ax,word ptr [bx+8]
- mov word ptr [bp-14],ax
- mov ax,word ptr [bx+10]
- mov word ptr [bp-16],ax
- ;
- ; c2min = boxp->c2min; c2max = boxp->c2max;
- ;
- ;
- mov ax,word ptr [bp-8]
- cmp ax,word ptr [bp-6]
- jle short @4@314
- ;
- ; if (c0max > c0min)
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@290
- @4@74:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++)
- ;
- mov di,word ptr [bp-10]
- jmp short @4@242
- @4@98:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-14]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-14]
- jmp short @4@194
- @4@122:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++)
- ;
- les bx,dword ptr [bp-4]
- add word ptr [bp-4],2
- cmp word ptr es:[bx],0
- je short @4@170
- ;
- ; if (*histp++ != 0) {
- ;
- mov ax,cx
- mov word ptr [bp-6],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx],ax
- ;
- ; boxp->c0min = c0min = c0;
- ;
- jmp short @4@314
- @4@170:
- inc si
- @4@194:
- cmp si,word ptr [bp-16]
- jle short @4@122
- inc di
- @4@242:
- cmp di,word ptr [bp-12]
- jle short @4@98
- inc cx
- @4@290:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@74
- @4@314:
- ;
- ; goto have_c0min;
- ; }
- ; }
- ; have_c0min:
- ;
- mov ax,word ptr [bp-8]
- cmp ax,word ptr [bp-6]
- jle short @4@602
- ;
- ; if (c0max > c0min)
- ;
- mov cx,ax
- jmp short @4@578
- @4@362:
- ;
- ; for (c0 = c0max; c0 >= c0min; c0--)
- ;
- mov di,word ptr [bp-10]
- jmp short @4@530
- @4@386:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-14]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-14]
- jmp short @4@482
- @4@410:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++)
- ;
- les bx,dword ptr [bp-4]
- add word ptr [bp-4],2
- cmp word ptr es:[bx],0
- je short @4@458
- ;
- ; if (*histp++ != 0) {
- ;
- mov ax,cx
- mov word ptr [bp-8],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx+2],ax
- ;
- ; boxp->c0max = c0max = c0;
- ;
- jmp short @4@602
- @4@458:
- inc si
- @4@482:
- cmp si,word ptr [bp-16]
- jle short @4@410
- inc di
- @4@530:
- cmp di,word ptr [bp-12]
- jle short @4@386
- dec cx
- @4@578:
- mov ax,cx
- cmp ax,word ptr [bp-6]
- jge short @4@362
- @4@602:
- ;
- ; goto have_c0max;
- ; }
- ; }
- ; have_c0max:
- ;
- mov ax,word ptr [bp-12]
- cmp ax,word ptr [bp-10]
- jle short @4@890
- ;
- ; if (c1max > c1min)
- ;
- mov di,word ptr [bp-10]
- jmp short @4@866
- @4@650:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++)
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@818
- @4@674:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-14]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-14]
- jmp short @4@770
- @4@698:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++)
- ;
- les bx,dword ptr [bp-4]
- add word ptr [bp-4],2
- cmp word ptr es:[bx],0
- je short @4@746
- ;
- ; if (*histp++ != 0) {
- ;
- mov ax,di
- mov word ptr [bp-10],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx+4],ax
- ;
- ; boxp->c1min = c1min = c1;
- ;
- jmp short @4@890
- @4@746:
- inc si
- @4@770:
- cmp si,word ptr [bp-16]
- jle short @4@698
- inc cx
- @4@818:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@674
- inc di
- @4@866:
- cmp di,word ptr [bp-12]
- jle short @4@650
- @4@890:
- ;
- ; goto have_c1min;
- ; }
- ; }
- ; have_c1min:
- ;
- mov ax,word ptr [bp-12]
- cmp ax,word ptr [bp-10]
- jle short @4@1178
- ;
- ; if (c1max > c1min)
- ;
- mov di,word ptr [bp-12]
- jmp short @4@1154
- @4@938:
- ;
- ; for (c1 = c1max; c1 >= c1min; c1--)
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@1106
- @4@962:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-14]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-14]
- jmp short @4@1058
- @4@986:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++)
- ;
- les bx,dword ptr [bp-4]
- add word ptr [bp-4],2
- cmp word ptr es:[bx],0
- je short @4@1034
- ;
- ; if (*histp++ != 0) {
- ;
- mov ax,di
- mov word ptr [bp-12],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx+6],ax
- ;
- ; boxp->c1max = c1max = c1;
- ;
- jmp short @4@1178
- @4@1034:
- inc si
- @4@1058:
- cmp si,word ptr [bp-16]
- jle short @4@986
- inc cx
- @4@1106:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@962
- dec di
- @4@1154:
- cmp di,word ptr [bp-10]
- jge short @4@938
- @4@1178:
- ;
- ; goto have_c1max;
- ; }
- ; }
- ; have_c1max:
- ;
- mov ax,word ptr [bp-16]
- cmp ax,word ptr [bp-14]
- jle short @4@1466
- ;
- ; if (c2max > c2min)
- ;
- mov si,word ptr [bp-14]
- jmp short @4@1442
- @4@1226:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++)
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@1394
- @4@1250:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,word ptr [bp-10]
- shl bx,6
- add dx,bx
- mov bx,si
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1min][c2];
- ;
- mov di,word ptr [bp-10]
- jmp short @4@1346
- @4@1274:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C_ELEMS)
- ;
- les bx,dword ptr [bp-4]
- cmp word ptr es:[bx],0
- je short @4@1322
- ;
- ; if (*histp != 0) {
- ;
- mov ax,si
- mov word ptr [bp-14],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx+8],ax
- ;
- ; boxp->c2min = c2min = c2;
- ;
- jmp short @4@1466
- @4@1322:
- inc di
- add word ptr [bp-4],64
- @4@1346:
- cmp di,word ptr [bp-12]
- jle short @4@1274
- inc cx
- @4@1394:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@1250
- inc si
- @4@1442:
- cmp si,word ptr [bp-16]
- jle short @4@1226
- @4@1466:
- ;
- ; goto have_c2min;
- ; }
- ; }
- ; have_c2min:
- ;
- mov ax,word ptr [bp-16]
- cmp ax,word ptr [bp-14]
- jle short @4@1754
- ;
- ; if (c2max > c2min)
- ;
- mov si,word ptr [bp-16]
- jmp short @4@1730
- @4@1514:
- ;
- ; for (c2 = c2max; c2 >= c2min; c2--)
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@1682
- @4@1538:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,word ptr [bp-10]
- shl bx,6
- add dx,bx
- mov bx,si
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1min][c2];
- ;
- mov di,word ptr [bp-10]
- jmp short @4@1634
- @4@1562:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C_ELEMS)
- ;
- les bx,dword ptr [bp-4]
- cmp word ptr es:[bx],0
- je short @4@1610
- ;
- ; if (*histp != 0) {
- ;
- mov ax,si
- mov word ptr [bp-16],ax
- mov bx,word ptr [bp+4]
- mov word ptr [bx+10],ax
- ;
- ; boxp->c2max = c2max = c2;
- ;
- jmp short @4@1754
- @4@1610:
- inc di
- add word ptr [bp-4],64
- @4@1634:
- cmp di,word ptr [bp-12]
- jle short @4@1562
- inc cx
- @4@1682:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@1538
- dec si
- @4@1730:
- cmp si,word ptr [bp-14]
- jge short @4@1514
- @4@1754:
- ;
- ; goto have_c2max;
- ; }
- ; }
- ; have_c2max:
- ;
- ; /* Now scan remaining volume of box and compute population */
- ;
- mov word ptr [bp-18],0
- mov word ptr [bp-20],0
- ;
- ; ccount = 0;
- ;
- mov ax,word ptr [bp-6]
- mov cx,ax
- jmp short @4@1994
- @4@1778:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++)
- ;
- mov di,word ptr [bp-10]
- jmp short @4@1946
- @4@1802:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++) {
- ;
- mov ax,cx
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-14]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-14]
- jmp short @4@1898
- @4@1826:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++, histp++)
- ;
- les bx,dword ptr [bp-4]
- cmp word ptr es:[bx],0
- je short @4@1874
- ;
- ; if (*histp != 0) {
- ;
- add word ptr [bp-20],1
- adc word ptr [bp-18],0
- @4@1874:
- inc si
- add word ptr [bp-4],2
- @4@1898:
- cmp si,word ptr [bp-16]
- jle short @4@1826
- inc di
- @4@1946:
- cmp di,word ptr [bp-12]
- jle short @4@1802
- inc cx
- @4@1994:
- mov ax,cx
- cmp ax,word ptr [bp-8]
- jle short @4@1778
- ;
- ; ccount++;
- ; }
- ; }
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bp-18]
- mov dx,word ptr [bp-20]
- mov word ptr [bx+14],ax
- mov word ptr [bx+12],dx
- ;
- ; boxp->colorcount = ccount;
- ;
- pop di
- pop si
- leave
- ret
- update_box endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- median_cut proc near
- push bp
- mov bp,sp
- sub sp,12
- push si
- push di
- jmp @5@482
- @5@50:
- ;
- ; median_cut (int desired_colors)
- ; /* Repeatedly select and split the largest box until we have enough boxes */
- ; {
- ; int n,lb;
- ; int c0,c1,c2,cmax;
- ; register boxptr b1,b2;
- ;
- ; while (numboxes < desired_colors) {
- ; /* Select box to split */
- ; /* Current algorithm: by population for first half, then by volume */
- ;
- mov ax,word ptr DGROUP:numboxes
- shl ax,1
- cmp ax,word ptr [bp+4]
- jg short @5@98
- ;
- ; if (numboxes*2 <= desired_colors) {
- ;
- call near ptr find_biggest_color_pop
- jmp short @5@122
- @5@98:
- ;
- ; b1 = find_biggest_color_pop();
- ; } else {
- ;
- call near ptr find_biggest_volume
- @5@122:
- mov si,ax
- ;
- ; b1 = find_biggest_volume();
- ; }
- ;
- or si,si
- jne @@3
- jmp @5@506
- @@3:
- ;
- ; if (b1 == NULL) /* no splittable boxes left! */
- ; break;
- ;
- mov ax,word ptr DGROUP:numboxes
- shl ax,4
- mov dx,word ptr DGROUP:boxlist
- add dx,ax
- mov di,dx
- ;
- ; b2 = &boxlist[numboxes]; /* where new box will go */
- ; /* Copy the color bounds to the new box. */
- ;
- mov ax,word ptr [si+2]
- mov word ptr [di+2],ax
- mov ax,word ptr [si+6]
- mov word ptr [di+6],ax
- mov ax,word ptr [si+10]
- mov word ptr [di+10],ax
- ;
- ; b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
- ;
- mov ax,word ptr [si]
- mov word ptr [di],ax
- mov ax,word ptr [si+4]
- mov word ptr [di+4],ax
- mov ax,word ptr [si+8]
- mov word ptr [di+8],ax
- ;
- ; b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
- ; /* Choose which axis to split the box on.
- ; * Current algorithm: longest scaled axis.
- ; * See notes in find_biggest_volume about scaling...
- ; */
- ;
- mov ax,word ptr [si+2]
- sub ax,word ptr [si]
- shl ax,1
- mov word ptr [bp-6],ax
- ;
- ; c0 = (b1->c0max - b1->c0min) * Y_SCALE;
- ;
- mov ax,word ptr [si+6]
- sub ax,word ptr [si+4]
- shl ax,1
- mov word ptr [bp-8],ax
- ;
- ; c1 = (b1->c1max - b1->c1min) << (HIST_Y_BITS-HIST_C_BITS);
- ;
- mov ax,word ptr [si+10]
- sub ax,word ptr [si+8]
- shl ax,1
- mov word ptr [bp-10],ax
- ;
- ; c2 = (b1->c2max - b1->c2min) << (HIST_Y_BITS-HIST_C_BITS);
- ;
- mov ax,word ptr [bp-6]
- mov word ptr [bp-12],ax
- mov word ptr [bp-2],0
- ;
- ; cmax = c0; n = 0;
- ;
- mov ax,word ptr [bp-8]
- cmp ax,word ptr [bp-12]
- jle short @5@218
- mov word ptr [bp-12],ax
- mov word ptr [bp-2],1
- @5@218:
- ;
- ; if (c1 > cmax) { cmax = c1; n = 1; }
- ;
- mov ax,word ptr [bp-10]
- cmp ax,word ptr [bp-12]
- jle short @5@266
- mov word ptr [bp-2],2
- @5@266:
- ;
- ; if (c2 > cmax) { n = 2; }
- ; /* Choose split point along selected axis, and update box bounds.
- ; * Current algorithm: split at halfway point.
- ; * (Since the box has been shrunk to minimum volume,
- ; * any split will produce two nonempty subboxes.)
- ; * Note that lb value is max for lower box, so must be < old max.
- ; */
- ;
- mov ax,word ptr [bp-2]
- or ax,ax
- je short @5@386
- cmp ax,1
- je short @5@410
- cmp ax,2
- je short @5@434
- jmp short @5@458
- @5@386:
- ;
- ; switch (n) {
- ; case 0:
- ;
- mov ax,word ptr [si+2]
- add ax,word ptr [si]
- mov bx,2
- cwd
- idiv bx
- mov word ptr [bp-4],ax
- ;
- ; lb = (b1->c0max + b1->c0min) / 2;
- ;
- mov word ptr [si+2],ax
- ;
- ; b1->c0max = lb;
- ;
- inc ax
- mov word ptr [di],ax
- ;
- ; b2->c0min = lb+1;
- ;
- jmp short @5@458
- @5@410:
- ;
- ; break;
- ; case 1:
- ;
- mov ax,word ptr [si+6]
- add ax,word ptr [si+4]
- mov bx,2
- cwd
- idiv bx
- mov word ptr [bp-4],ax
- ;
- ; lb = (b1->c1max + b1->c1min) / 2;
- ;
- mov word ptr [si+6],ax
- ;
- ; b1->c1max = lb;
- ;
- inc ax
- mov word ptr [di+4],ax
- ;
- ; b2->c1min = lb+1;
- ;
- jmp short @5@458
- @5@434:
- ;
- ; break;
- ; case 2:
- ;
- mov ax,word ptr [si+10]
- add ax,word ptr [si+8]
- mov bx,2
- cwd
- idiv bx
- mov word ptr [bp-4],ax
- ;
- ; lb = (b1->c2max + b1->c2min) / 2;
- ;
- mov word ptr [si+10],ax
- ;
- ; b1->c2max = lb;
- ;
- inc ax
- mov word ptr [di+8],ax
- ;
- ; b2->c2min = lb+1;
- ;
- @5@458:
- ;
- ; break;
- ; }
- ; /* Update stats for boxes */
- ;
- push si
- call near ptr update_box
- inc sp
- inc sp
- ;
- ; update_box(b1);
- ;
- push di
- call near ptr update_box
- inc sp
- inc sp
- ;
- ; update_box(b2);
- ;
- inc word ptr DGROUP:numboxes
- @5@482:
- mov ax,word ptr DGROUP:numboxes
- cmp ax,word ptr [bp+4]
- jge @@4
- jmp @5@50
- @@4:
- @5@506:
- ;
- ; numboxes++;
- ; }
- ;
- pop di
- pop si
- leave
- ret
- median_cut endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- compute_color proc near
- push bp
- mov bp,sp
- sub sp,38
- push si
- push di
- ;
- ; compute_color (boxptr boxp, int icolor)
- ; /* Compute representative color for a box, put it in my_colormap[icolor] */
- ; {
- ; /* Current algorithm: mean weighted by pixels (not colors) */
- ; /* Note it is important to get the rounding correct! */
- ; histptr histp;
- ; int c0,c1,c2;
- ; int c0min,c0max,c1min,c1max,c2min,c2max;
- ; long count;
- ;
- mov word ptr [bp-24],0
- mov word ptr [bp-26],0
- ;
- ; long total = 0;
- ;
- mov word ptr [bp-28],0
- mov word ptr [bp-30],0
- ;
- ; long c0total = 0;
- ;
- mov word ptr [bp-32],0
- mov word ptr [bp-34],0
- ;
- ; long c1total = 0;
- ;
- mov word ptr [bp-36],0
- mov word ptr [bp-38],0
- ;
- ; long c2total = 0;
- ;
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx]
- mov word ptr [bp-8],ax
- mov ax,word ptr [bx+2]
- mov word ptr [bp-10],ax
- ;
- ; c0min = boxp->c0min; c0max = boxp->c0max;
- ;
- mov ax,word ptr [bx+4]
- mov word ptr [bp-12],ax
- mov ax,word ptr [bx+6]
- mov word ptr [bp-14],ax
- ;
- ; c1min = boxp->c1min; c1max = boxp->c1max;
- ;
- mov ax,word ptr [bx+8]
- mov word ptr [bp-16],ax
- mov ax,word ptr [bx+10]
- mov word ptr [bp-18],ax
- ;
- ; c2min = boxp->c2min; c2max = boxp->c2max;
- ;
- ;
- mov ax,word ptr [bp-8]
- mov word ptr [bp-6],ax
- jmp @6@266
- @6@50:
- ;
- ; for (c0 = c0min; c0 <= c0max; c0++)
- ;
- mov di,word ptr [bp-12]
- jmp @6@218
- @6@74:
- ;
- ; for (c1 = c1min; c1 <= c1max; c1++) {
- ;
- mov ax,word ptr [bp-6]
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-16]
- shl bx,1
- add dx,bx
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; histp = & histogram[c0][c1][c2min];
- ;
- mov si,word ptr [bp-16]
- jmp short @6@170
- @6@98:
- ;
- ; for (c2 = c2min; c2 <= c2max; c2++) {
- ;
- les bx,dword ptr [bp-4]
- add word ptr [bp-4],2
- mov ax,word ptr es:[bx]
- xor dx,dx
- mov word ptr [bp-20],dx
- mov word ptr [bp-22],ax
- or ax,dx
- je short @6@146
- ;
- ; if ((count = *histp++) != 0) {
- ;
- .386
- mov eax, [bp-22]
- add [bp-26], eax
- ;
- ; total += count;
- ;
- movsx edx, word ptr [bp-6]
- shl edx, 2
- add edx, 2
- imul edx, eax
- add [bp-30], edx
- ;
- ; c0total += ((c0 << Y_SHIFT) + ((1<<Y_SHIFT)>>1)) * count;
- ;
- movsx edx, di
- shl edx, 3
- add edx, 4
- imul edx, eax
- add [bp-34], edx
- ;
- ; c1total += ((c1 << C_SHIFT) + ((1<<C_SHIFT)>>1)) * count;
- ;
- movsx edx, si
- shl edx, 3
- add edx, 4
- imul edx, eax
- add [bp-38], edx
- .286
- @6@146:
- inc si
- @6@170:
- cmp si,word ptr [bp-18]
- jle short @6@98
- inc di
- @6@218:
- cmp di,word ptr [bp-14]
- jg @@5
- jmp @6@74
- @@5:
- inc word ptr [bp-6]
- @6@266:
- mov ax,word ptr [bp-6]
- cmp ax,word ptr [bp-10]
- jg @@6
- jmp @6@50
- @@6:
- ;
- ; c2total += ((c2 << C_SHIFT) + ((1<<C_SHIFT)>>1)) * count;
- ; }
- ; }
- ; }
- ;
- ;
- ;mov eax, [bp-26]
- ;mov edx, eax
- ;sar edx, 1
- push word ptr [bp-24]
- push word ptr [bp-26]
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- sar ax,1
- rcr dx,1
- mov bx,word ptr [bp-28]
- mov cx,word ptr [bp-30]
- add cx,dx
- adc bx,ax
- push bx
- push cx
- call near ptr N_LDIV@
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx]
- add bx,word ptr [bp+6]
- mov byte ptr es:[bx],al
- ;
- ; my_colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
- ;
- push word ptr [bp-24]
- push word ptr [bp-26]
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- sar ax,1
- rcr dx,1
- mov bx,word ptr [bp-32]
- mov cx,word ptr [bp-34]
- add cx,dx
- adc bx,ax
- push bx
- push cx
- call near ptr N_LDIV@
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+4]
- add bx,word ptr [bp+6]
- mov byte ptr es:[bx],al
- ;
- ; my_colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
- ;
- push word ptr [bp-24]
- push word ptr [bp-26]
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- sar ax,1
- rcr dx,1
- mov bx,word ptr [bp-36]
- mov cx,word ptr [bp-38]
- add cx,dx
- adc bx,ax
- push bx
- push cx
- call near ptr N_LDIV@
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+8]
- add bx,word ptr [bp+6]
- mov byte ptr es:[bx],al
- ;
- ; my_colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
- ;
- pop di
- pop si
- leave
- ret
- compute_color endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- remap_colormap proc near
- push bp
- mov bp,sp
- sub sp,26
- push si
- push di
- mov di,word ptr [bp+4]
- ;
- ; remap_colormap (decompress_info_ptr cinfo)
- ; /* Remap the internal colormap to the output colorspace */
- ; {
- ; /* This requires a little trickery since color_convert expects to
- ; * deal with 3-D arrays (a 2-D sample array for each component).
- ; * We must promote the colormaps into one-row 3-D arrays.
- ; */
- ; short ci;
- ; JSAMPARRAY input_hack[3];
- ; JSAMPARRAY output_hack[10]; /* assume no more than 10 output components */
- ;
- ;
- xor si,si
- jmp short @7@98
- @7@50:
- ;
- ; for (ci = 0; ci < 3; ci++)
- ;
- mov bx,si
- shl bx,1
- lea ax,word ptr [bp-6]
- add bx,ax
- mov ax,si
- shl ax,2
- mov dx,word ptr DGROUP:my_colormap
- add dx,ax
- mov word ptr [bx],dx
- inc si
- @7@98:
- cmp si,3
- jl short @7@50
- ;
- ; input_hack[ci] = &(my_colormap[ci]);
- ;
- xor si,si
- jmp short @7@194
- @7@146:
- ;
- ; for (ci = 0; ci < cinfo->color_out_comps; ci++)
- ;
- mov ax,si
- shl ax,2
- mov dx,word ptr [di+145]
- add dx,ax
- mov bx,si
- shl bx,1
- lea ax,word ptr [bp-26]
- add bx,ax
- mov word ptr [bx],dx
- inc si
- @7@194:
- cmp word ptr [di+139],si
- jg short @7@146
- ;
- ; output_hack[ci] = &(cinfo->colormap[ci]);
- ;
- ;
- ;
- ; (*cinfo->methods->color_convert) (cinfo, 1,
- ; (long) cinfo->actual_number_of_colors,
- ;
- lea ax,word ptr [bp-26]
- push ax
- lea ax,word ptr [bp-6]
- push ax
- mov ax,word ptr [di+143]
- cwd
- push dx
- push ax
- push 1
- push di
- mov bx,word ptr [di]
- call word ptr [bx+44]
- add sp,12
- ;
- ; input_hack, output_hack);
- ;
- pop di
- pop si
- leave
- ret
- remap_colormap endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- select_colors proc near
- push bp
- mov bp,sp
- dec sp
- dec sp
- push si
- push di
- mov si,word ptr [bp+4]
- ;
- ; select_colors (decompress_info_ptr cinfo)
- ; /* Master routine for color selection */
- ; {
- ;
- mov ax,word ptr [si+24]
- mov word ptr [bp-2],ax
- ;
- ; int desired = cinfo->desired_number_of_colors;
- ; int i;
- ;
- ; /* Allocate workspace for box list */
- ;
- shl ax,4
- push ax
- mov bx,word ptr [si+2]
- call word ptr [bx+22]
- inc sp
- inc sp
- mov word ptr DGROUP:boxlist,ax
- ;
- ; boxlist = (boxptr) (*cinfo->emethods->alloc_small) (desired * SIZEOF(box));
- ; /* Initialize one box containing whole space */
- ;
- mov word ptr DGROUP:numboxes,1
- ;
- ; numboxes = 1;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx],0
- ;
- ; boxlist[0].c0min = 0;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx+2],63
- ;
- ; boxlist[0].c0max = MAXJSAMPLE >> Y_SHIFT;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx+4],0
- ;
- ; boxlist[0].c1min = 0;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx+6],31
- ;
- ; boxlist[0].c1max = MAXJSAMPLE >> C_SHIFT;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx+8],0
- ;
- ; boxlist[0].c2min = 0;
- ;
- mov bx,word ptr DGROUP:boxlist
- mov word ptr [bx+10],31
- ;
- ; boxlist[0].c2max = MAXJSAMPLE >> C_SHIFT;
- ; /* Shrink it to actually-used volume and set its statistics */
- ;
- push word ptr DGROUP:boxlist
- call near ptr update_box
- inc sp
- inc sp
- ;
- ; update_box(& boxlist[0]);
- ; /* Perform median-cut to produce final box list */
- ;
- push word ptr [bp-2]
- call near ptr median_cut
- inc sp
- inc sp
- ;
- ; median_cut(desired);
- ; /* Compute the representative color for each box, fill my_colormap[] */
- ;
- xor di,di
- jmp short @8@98
- @8@50:
- ;
- ; for (i = 0; i < numboxes; i++)
- ;
- push di
- mov ax,di
- shl ax,4
- mov dx,word ptr DGROUP:boxlist
- add dx,ax
- push dx
- call near ptr compute_color
- add sp,4
- inc di
- @8@98:
- cmp di,word ptr DGROUP:numboxes
- jl short @8@50
- ;
- ; compute_color(& boxlist[i], i);
- ;
- mov ax,word ptr DGROUP:numboxes
- mov word ptr [si+143],ax
- ;
- ; cinfo->actual_number_of_colors = numboxes;
- ; /* Produce an output colormap in the desired output colorspace */
- ;
- push si
- call near ptr remap_colormap
- inc sp
- inc sp
- ;
- ; remap_colormap(cinfo);
- ; TRACEMS1(cinfo->emethods, 1, "Selected %d colors for quantization",
- ;
- mov bx,word ptr [si+2]
- cmp word ptr [bx+4],1
- jl short @8@194
- mov bx,word ptr [si+2]
- mov ax,word ptr DGROUP:numboxes
- mov word ptr [bx+6],ax
- push offset DGROUP:s@
- mov bx,word ptr [si+2]
- call word ptr [bx+2]
- inc sp
- inc sp
- @8@194:
- ;
- ; numboxes);
- ; /* Done with the box list */
- ;
- push word ptr DGROUP:boxlist
- mov bx,word ptr [si+2]
- call word ptr [bx+24]
- inc sp
- inc sp
- ;
- ; (*cinfo->emethods->free_small) ((void *) boxlist);
- ;
- pop di
- pop si
- leave
- ret
- select_colors endp
- ;
- ; LOCAL int
- ;
- assume cs:_TEXT
- find_nearby_colors proc near
- push bp
- mov bp,sp
- sub sp,1058
- push si
- push di
- mov di,word ptr [bp+6]
- ;
- ; find_nearby_colors (decompress_info_ptr cinfo, int minc0, int minc1, int minc2,
- ; JSAMPLE colorlist[])
- ; /* Locate the colormap entries close enough to an update box to be candidates
- ; * for the nearest entry to some cell(s) in the update box. The update box
- ; * is specified by the center coordinates of its first cell. The number of
- ; * candidate colormap entries is returned, and their colormap indexes are
- ; * placed in colorlist[].
- ; * This routine uses Heckbert's "locally sorted search" criterion to select
- ; * the colors that need further consideration.
- ; */
- ; {
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx+143]
- mov word ptr [bp-2],ax
- ;
- ; int numcolors = cinfo->actual_number_of_colors;
- ; int maxc0, maxc1, maxc2;
- ; int centerc0, centerc1, centerc2;
- ; int i, x, ncolors;
- ; INT32 minmaxdist, min_dist, max_dist, tdist;
- ; INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
- ;
- ; /* Compute true coordinates of update box's upper corner and center.
- ; * Actually we compute the coordinates of the center of the upper-corner
- ; * histogram cell, which are the upper bounds of the volume we care about.
- ; * Note that since ">>" rounds down, the "center" values may be closer to
- ; * min than to max; hence comparisons to them must be "<=", not "<".
- ; */
- ;
- mov ax,di
- add ax,28
- mov word ptr [bp-4],ax
- ;
- ; maxc0 = minc0 + ((1 << BOX_Y_SHIFT) - (1 << Y_SHIFT));
- ;
- mov ax,di
- add ax,word ptr [bp-4]
- sar ax,1
- mov word ptr [bp-10],ax
- ;
- ; centerc0 = (minc0 + maxc0) >> 1;
- ;
- mov ax,word ptr [bp+8]
- add ax,24
- mov word ptr [bp-6],ax
- ;
- ; maxc1 = minc1 + ((1 << BOX_C_SHIFT) - (1 << C_SHIFT));
- ;
- mov ax,word ptr [bp+8]
- add ax,word ptr [bp-6]
- sar ax,1
- mov word ptr [bp-12],ax
- ;
- ; centerc1 = (minc1 + maxc1) >> 1;
- ;
- mov ax,word ptr [bp+10]
- add ax,24
- mov word ptr [bp-8],ax
- ;
- ; maxc2 = minc2 + ((1 << BOX_C_SHIFT) - (1 << C_SHIFT));
- ;
- mov ax,word ptr [bp+10]
- add ax,word ptr [bp-8]
- sar ax,1
- mov word ptr [bp-14],ax
- ;
- ; centerc2 = (minc2 + maxc2) >> 1;
- ;
- ; /* For each color in colormap, find:
- ; * 1. its minimum squared-distance to any point in the update box
- ; * (zero if color is within update box);
- ; * 2. its maximum squared-distance to any point in the update box.
- ; * Both of these can be found by considering only the corners of the box.
- ; * We save the minimum distance for each color in mindist[];
- ; * only the smallest maximum distance is of interest.
- ; * Note we have to scale Y to get correct distance in scaled space.
- ; */
- ;
- mov word ptr [bp-20],32767
- mov word ptr [bp-22],65535
- ;
- ; minmaxdist = 0x7FFFFFFFL;
- ;
- ;
- mov word ptr [bp-16],0
- jmp @9@746
- @9@50:
- ;
- ; for (i = 0; i < numcolors; i++) {
- ; /* We compute the squared-c0-distance term, then add in the other two. */
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx]
- add bx,word ptr [bp-16]
- mov al,byte ptr es:[bx]
- mov ah,0
- mov si,ax
- ;
- ; x = GETJSAMPLE(my_colormap[0][i]);
- ;
- cmp si,di
- jge short @9@98
- ;
- ; if (x < minc0) {
- ;
- sub ax,di
- shl ax,1
- cwd
- mov word ptr [bp-32],dx
- mov word ptr [bp-34],ax
- ;
- ; tdist = (x - minc0) * Y_SCALE;
- ;
- mov cx,word ptr [bp-32]
- mov bx,word ptr [bp-34]
- mov dx,word ptr [bp-32]
- call near ptr N_LXMUL@
- mov word ptr [bp-24],dx
- mov word ptr [bp-26],ax
- ;
- ; min_dist = tdist*tdist;
- ;
- mov ax,si
- sub ax,word ptr [bp-4]
- jmp short @9@218
- @9@98:
- ;
- ; tdist = (x - maxc0) * Y_SCALE;
- ; max_dist = tdist*tdist;
- ;
- cmp si,word ptr [bp-4]
- jle short @9@146
- ;
- ; } else if (x > maxc0) {
- ;
- mov ax,si
- sub ax,word ptr [bp-4]
- shl ax,1
- cwd
- mov word ptr [bp-32],dx
- mov word ptr [bp-34],ax
- ;
- ; tdist = (x - maxc0) * Y_SCALE;
- ;
- mov cx,word ptr [bp-32]
- mov bx,word ptr [bp-34]
- mov dx,word ptr [bp-32]
- call near ptr N_LXMUL@
- mov word ptr [bp-24],dx
- mov word ptr [bp-26],ax
- jmp short @9@194
- @9@146:
- ;
- ; min_dist = tdist*tdist;
- ; tdist = (x - minc0) * Y_SCALE;
- ; max_dist = tdist*tdist;
- ; } else {
- ; /* within cell range so no contribution to min_dist */
- ;
- mov word ptr [bp-24],0
- mov word ptr [bp-26],0
- ;
- ; min_dist = 0;
- ;
- cmp si,word ptr [bp-10]
- jg short @9@194
- ;
- ; if (x <= centerc0) {
- ;
- mov ax,si
- sub ax,word ptr [bp-4]
- jmp short @9@218
- @9@194:
- ;
- ; tdist = (x - maxc0) * Y_SCALE;
- ; max_dist = tdist*tdist;
- ; } else {
- ;
- mov ax,si
- sub ax,di
- @9@218:
- shl ax,1
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = (x - minc0) * Y_SCALE;
- ;
- imul edx, edx
- mov [bp-30], edx
- .286
- ;
- ; max_dist = tdist*tdist;
- ; }
- ; }
- ;
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+4]
- add bx,word ptr [bp-16]
- mov al,byte ptr es:[bx]
- mov ah,0
- mov si,ax
- ;
- ; x = GETJSAMPLE(my_colormap[1][i]);
- ;
- cmp si,word ptr [bp+8]
- jge short @9@290
- ;
- ; if (x < minc1) {
- ;
- sub ax,word ptr [bp+8]
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = x - minc1;
- ;
- imul edx, edx
- add [bp-26], edx
- .286
- ;
- ; min_dist += tdist*tdist;
- ;
- mov ax,si
- sub ax,word ptr [bp-6]
- jmp short @9@410
- @9@290:
- ;
- ; tdist = x - maxc1;
- ; max_dist += tdist*tdist;
- ;
- cmp si,word ptr [bp-6]
- jle short @9@338
- ;
- ; } else if (x > maxc1) {
- ;
- mov ax,si
- sub ax,word ptr [bp-6]
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = x - maxc1;
- ;
- imul edx, edx
- add [bp-36], edx
- .286
- jmp short @9@386
- @9@338:
- ;
- ; min_dist += tdist*tdist;
- ; tdist = x - minc1;
- ; max_dist += tdist*tdist;
- ; } else {
- ; /* within cell range so no contribution to min_dist */
- ;
- cmp si,word ptr [bp-12]
- jg short @9@386
- ;
- ; if (x <= centerc1) {
- ;
- mov ax,si
- sub ax,word ptr [bp-6]
- jmp short @9@410
- @9@386:
- ;
- ; tdist = x - maxc1;
- ; max_dist += tdist*tdist;
- ; } else {
- ;
- mov ax,si
- sub ax,word ptr [bp+8]
- @9@410:
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = x - minc1;
- ;
- imul edx, edx
- add [bp-30], edx
- .286
- ;
- ; max_dist += tdist*tdist;
- ; }
- ; }
- ;
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+8]
- add bx,word ptr [bp-16]
- mov al,byte ptr es:[bx]
- mov ah,0
- mov si,ax
- ;
- ; x = GETJSAMPLE(my_colormap[2][i]);
- ;
- cmp si,word ptr [bp+10]
- jge short @9@482
- ;
- ; if (x < minc2) {
- ;
- sub ax,word ptr [bp+10]
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = x - minc2;
- ;
- imul edx, edx
- add [bp-26], edx
- .286
- ;
- ; min_dist += tdist*tdist;
- ;
- mov ax,si
- sub ax,word ptr [bp-8]
- jmp short @9@602
- @9@482:
- ;
- ; tdist = x - maxc2;
- ; max_dist += tdist*tdist;
- ;
- cmp si,word ptr [bp-8]
- jle short @9@530
- ;
- ; } else if (x > maxc2) {
- ;
- mov ax,si
- sub ax,word ptr [bp-8]
- .386
- movsx edx, ax
- mov [bp-34], edx
- ;
- ; tdist = x - maxc2;
- ;
- imul edx, edx
- add [bp-26], edx
- .286
- jmp short @9@578
- @9@530:
- ;
- ; min_dist += tdist*tdist;
- ; tdist = x - minc2;
- ; max_dist += tdist*tdist;
- ; } else {
- ; /* within cell range so no contribution to min_dist */
- ;
- cmp si,word ptr [bp-14]
- jg short @9@578
- ;
- ; if (x <= centerc2) {
- ;
- mov ax,si
- sub ax,word ptr [bp-8]
- jmp short @9@602
- @9@578:
- ;
- ; tdist = x - maxc2;
- ; max_dist += tdist*tdist;
- ; } else {
- ;
- mov ax,si
- sub ax,word ptr [bp+10]
- @9@602:
- .386
- movsx ecx, ax
- mov [bp-34], ecx
- ;
- ; tdist = x - minc2;
- ;
- imul ecx, ecx
- add [bp-30], ecx
- .286
- ;
- ; max_dist += tdist*tdist;
- ; }
- ; }
- ;
- ;
- mov bx,word ptr [bp-16]
- shl bx,2
- lea ax,word ptr [bp-1058]
- add bx,ax
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- mov word ptr [bx+2],ax
- mov word ptr [bx],dx
- ;
- ; mindist[i] = min_dist; /* save away the results */
- ;
- mov ax,word ptr [bp-28]
- mov dx,word ptr [bp-30]
- cmp ax,word ptr [bp-20]
- jg short @9@722
- jl short @9@698
- cmp dx,word ptr [bp-22]
- jae short @9@722
- @9@698:
- ;
- ; if (max_dist < minmaxdist)
- ;
- mov ax,word ptr [bp-28]
- mov dx,word ptr [bp-30]
- mov word ptr [bp-20],ax
- mov word ptr [bp-22],dx
- @9@722:
- inc word ptr [bp-16]
- @9@746:
- mov ax,word ptr [bp-16]
- cmp ax,word ptr [bp-2]
- jge @@7
- jmp @9@50
- @@7:
- ;
- ; minmaxdist = max_dist;
- ; }
- ;
- ; /* Now we know that no cell in the update box is more than minmaxdist
- ; * away from some colormap entry. Therefore, only colors that are
- ; * within minmaxdist of some part of the box need be considered.
- ; */
- ;
- mov word ptr [bp-18],0
- ;
- ; ncolors = 0;
- ;
- mov word ptr [bp-16],0
- jmp short @9@914
- @9@794:
- ;
- ; for (i = 0; i < numcolors; i++) {
- ;
- mov bx,word ptr [bp-16]
- shl bx,2
- lea ax,word ptr [bp-1058]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- cmp ax,word ptr [bp-20]
- jg short @9@890
- jne short @9@866
- cmp dx,word ptr [bp-22]
- ja short @9@890
- @9@866:
- ;
- ; if (mindist[i] <= minmaxdist)
- ;
- mov bx,word ptr [bp+12]
- add bx,word ptr [bp-18]
- mov al,byte ptr [bp-16]
- mov byte ptr [bx],al
- inc word ptr [bp-18]
- @9@890:
- inc word ptr [bp-16]
- @9@914:
- mov ax,word ptr [bp-16]
- cmp ax,word ptr [bp-2]
- jl short @9@794
- ;
- ; colorlist[ncolors++] = (JSAMPLE) i;
- ; }
- ;
- mov ax,word ptr [bp-18]
- ;
- ; return ncolors;
- ;
- pop di
- pop si
- leave
- ret
- find_nearby_colors endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- find_best_colors proc near
- push bp
- mov bp,sp
- sub sp,558
- push si
- push di
- ;
- ; find_best_colors (decompress_info_ptr cinfo, int minc0, int minc1, int minc2,
- ; int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
- ; /* Find the closest colormap entry for each cell in the update box,
- ; * given the list of candidate colors prepared by find_nearby_colors.
- ; * Return the indexes of the closest entries in the bestcolor[] array.
- ; * This routine uses Thomas' incremental distance calculation method to
- ; * find the distance from a colormap entry to successive cells in the box.
- ; */
- ; {
- ; int ic0, ic1, ic2;
- ; int i, icolor;
- ; register INT32 * bptr; /* pointer into bestdist[] array */
- ; JSAMPLE * cptr; /* pointer into bestcolor[] array */
- ; INT32 dist0, dist1; /* initial distance values */
- ; register INT32 dist2; /* current distance in inner loop */
- ; INT32 xx0, xx1; /* distance increments */
- ; register INT32 xx2;
- ; INT32 inc0, inc1, inc2; /* initial values for increments */
- ; /* This array holds the distance to the nearest-so-far color for each cell */
- ; INT32 bestdist[BOX_Y_ELEMS * BOX_C_ELEMS * BOX_C_ELEMS];
- ;
- ; /* Initialize best-distance for each cell of the update box */
- ;
- lea ax,word ptr [bp-558]
- mov si,ax
- ;
- ; bptr = bestdist;
- ;
- mov word ptr [bp-8],127
- jmp short @10@98
- @10@50:
- ;
- ; for (i = BOX_Y_ELEMS*BOX_C_ELEMS*BOX_C_ELEMS-1; i >= 0; i--)
- ;
- mov word ptr [si+2],32767
- mov word ptr [si],65535
- add si,4
- dec word ptr [bp-8]
- @10@98:
- cmp word ptr [bp-8],0
- jge short @10@50
- ;
- ; *bptr++ = 0x7FFFFFFFL;
- ;
- ; /* For each color selected by find_nearby_colors,
- ; * compute its distance to the center of each cell in the box.
- ; * If that's less than best-so-far, update best distance and color number.
- ; * Note we have to scale Y to get correct distance in scaled space.
- ; */
- ;
- ; /* Nominal steps between cell centers ("x" in Thomas article) */
- ; #define STEP_Y ((1 << Y_SHIFT) * Y_SCALE)
- ; #define STEP_C (1 << C_SHIFT)
- ;
- ;
- mov word ptr [bp-8],0
- jmp @10@554
- @10@146:
- ;
- ; for (i = 0; i < numcolors; i++) {
- ;
- mov bx,word ptr [bp+14]
- add bx,word ptr [bp-8]
- mov al,byte ptr [bx]
- mov ah,0
- mov word ptr [bp-10],ax
- ;
- ; icolor = GETJSAMPLE(colorlist[i]);
- ; /* Compute (square of) distance from minc0/c1/c2 to this color */
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx]
- add bx,word ptr [bp-10]
- mov al,byte ptr es:[bx]
- mov ah,0
- push ax
- mov ax,word ptr [bp+6]
- pop dx
- sub ax,dx
- shl ax,1
- .386
- movsx edx, ax
- mov [bp-38], edx
- ;
- ; inc0 = (minc0 - (int) GETJSAMPLE(my_colormap[0][icolor])) * Y_SCALE;
- ;
- imul edx, edx
- mov [bp-14], edx
- .286
- ;
- ; dist0 = inc0*inc0;
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+4]
- add bx,word ptr [bp-10]
- mov al,byte ptr es:[bx]
- mov ah,0
- push ax
- mov ax,word ptr [bp+8]
- pop dx
- sub ax,dx
- .386
- movsx edx, ax
- mov [bp-42], edx
- ;
- ; inc1 = minc1 - (int) GETJSAMPLE(my_colormap[1][icolor]);
- ;
- imul edx, edx
- add [bp-14], edx
- .286
- ;
- ; dist0 += inc1*inc1;
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+8]
- add bx,word ptr [bp-10]
- mov al,byte ptr es:[bx]
- mov ah,0
- push ax
- mov ax,word ptr [bp+10]
- pop dx
- sub ax,dx
- .386
- movsx edx, ax
- mov [bp-46], edx
- ;
- ; inc2 = minc2 - (int) GETJSAMPLE(my_colormap[2][icolor]);
- ;
- imul edx, edx
- add [bp-14], edx
- ;
- ; dist0 += inc2*inc2;
- ; /* Form the initial difference increments */
- ;
- mov edx, [bp-38]
- sal edx, 4
- add edx, 64
- mov [bp-38], edx
- ;
- ; inc0 = inc0 * (2 * STEP_Y) + STEP_Y * STEP_Y;
- ;
- mov eax, [bp-42]
- sal eax, 4
- add eax, 64
- mov [bp-42], eax
- ;
- ; inc1 = inc1 * (2 * STEP_C) + STEP_C * STEP_C;
- ;
- mov edx, [bp-46]
- sal edx, 4
- add edx, 64
- mov [bp-46], edx
- .286
- ;
- ; inc2 = inc2 * (2 * STEP_C) + STEP_C * STEP_C;
- ; /* Now loop over all cells in box, updating distance per Thomas method */
- ;
- lea ax,word ptr [bp-558]
- mov si,ax
- ;
- ; bptr = bestdist;
- ;
- mov di,word ptr [bp+16]
- ;
- ; cptr = bestcolor;
- ;
- mov ax,word ptr [bp-36]
- mov dx,word ptr [bp-38]
- mov word ptr [bp-24],ax
- mov word ptr [bp-26],dx
- ;
- ; xx0 = inc0;
- ;
- mov word ptr [bp-2],7
- jmp @10@506
- @10@170:
- ;
- ; for (ic0 = BOX_Y_ELEMS-1; ic0 >= 0; ic0--) {
- ;
- mov ax,word ptr [bp-12]
- mov dx,word ptr [bp-14]
- mov word ptr [bp-16],ax
- mov word ptr [bp-18],dx
- ;
- ; dist1 = dist0;
- ;
- mov ax,word ptr [bp-40]
- mov dx,word ptr [bp-42]
- mov word ptr [bp-28],ax
- mov word ptr [bp-30],dx
- ;
- ; xx1 = inc1;
- ;
- mov word ptr [bp-4],3
- jmp short @10@434
- @10@194:
- ;
- ; for (ic1 = BOX_C_ELEMS-1; ic1 >= 0; ic1--) {
- ;
- mov ax,word ptr [bp-16]
- mov dx,word ptr [bp-18]
- mov word ptr [bp-20],ax
- mov word ptr [bp-22],dx
- ;
- ; dist2 = dist1;
- ;
- mov ax,word ptr [bp-44]
- mov dx,word ptr [bp-46]
- mov word ptr [bp-32],ax
- mov word ptr [bp-34],dx
- ;
- ; xx2 = inc2;
- ;
- mov word ptr [bp-6],3
- jmp short @10@362
- @10@218:
- ;
- ; for (ic2 = BOX_C_ELEMS-1; ic2 >= 0; ic2--) {
- ;
- mov ax,word ptr [si+2]
- mov dx,word ptr [si]
- cmp ax,word ptr [bp-20]
- jl short @10@314
- jg short @10@290
- cmp dx,word ptr [bp-22]
- jbe short @10@314
- @10@290:
- ;
- ; if (dist2 < *bptr) {
- ;
- mov ax,word ptr [bp-20]
- mov dx,word ptr [bp-22]
- mov word ptr [si+2],ax
- mov word ptr [si],dx
- ;
- ; *bptr = dist2;
- ;
- mov al,byte ptr [bp-10]
- mov byte ptr [di],al
- @10@314:
- ;
- ; *cptr = (JSAMPLE) icolor;
- ; }
- ;
- mov ax,word ptr [bp-32]
- mov dx,word ptr [bp-34]
- add word ptr [bp-22],dx
- adc word ptr [bp-20],ax
- ;
- ; dist2 += xx2;
- ;
- add word ptr [bp-34],128
- adc word ptr [bp-32],0
- ;
- ; xx2 += 2 * STEP_C * STEP_C;
- ;
- add si,4
- ;
- ; bptr++;
- ;
- inc di
- dec word ptr [bp-6]
- @10@362:
- cmp word ptr [bp-6],0
- jge short @10@218
- ;
- ; cptr++;
- ; }
- ;
- mov ax,word ptr [bp-28]
- mov dx,word ptr [bp-30]
- add word ptr [bp-18],dx
- adc word ptr [bp-16],ax
- ;
- ; dist1 += xx1;
- ;
- add word ptr [bp-30],128
- adc word ptr [bp-28],0
- dec word ptr [bp-4]
- @10@434:
- cmp word ptr [bp-4],0
- jge short @10@194
- ;
- ; xx1 += 2 * STEP_C * STEP_C;
- ; }
- ;
- mov ax,word ptr [bp-24]
- mov dx,word ptr [bp-26]
- add word ptr [bp-14],dx
- adc word ptr [bp-12],ax
- ;
- ; dist0 += xx0;
- ;
- add word ptr [bp-26],128
- adc word ptr [bp-24],0
- dec word ptr [bp-2]
- @10@506:
- cmp word ptr [bp-2],0
- jl @@8
- jmp @10@170
- @@8:
- inc word ptr [bp-8]
- @10@554:
- mov ax,word ptr [bp-8]
- cmp ax,word ptr [bp+12]
- jge @@9
- jmp @10@146
- @@9:
- ;
- ; xx0 += 2 * STEP_Y * STEP_Y;
- ; }
- ; }
- ;
- pop di
- pop si
- leave
- ret
- find_best_colors endp
- ;
- ; LOCAL void
- ;
- assume cs:_TEXT
- fill_inverse_cmap proc near
- push bp
- mov bp,sp
- sub sp,400
- push si
- push di
- ;
- ; fill_inverse_cmap (decompress_info_ptr cinfo, int c0, int c1, int c2)
- ; /* Fill the inverse-colormap entries in the update box that contains */
- ; /* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */
- ; /* we can fill as many others as we wish.) */
- ; {
- ; int minc0, minc1, minc2; /* lower left corner of update box */
- ; int ic0, ic1, ic2;
- ; register JSAMPLE * cptr; /* pointer into bestcolor[] array */
- ; register histptr cachep; /* pointer into main cache array */
- ; /* This array lists the candidate colormap indexes. */
- ; JSAMPLE colorlist[MAXNUMCOLORS];
- ; int numcolors; /* number of candidate colors */
- ; /* This array holds the actually closest colormap index for each cell. */
- ; JSAMPLE bestcolor[BOX_Y_ELEMS * BOX_C_ELEMS * BOX_C_ELEMS];
- ;
- ; /* Convert cell coordinates to update box ID */
- ;
- sar word ptr [bp+6],3
- ;
- ; c0 >>= BOX_Y_LOG;
- ;
- sar word ptr [bp+8],2
- ;
- ; c1 >>= BOX_C_LOG;
- ;
- sar word ptr [bp+10],2
- ;
- ; c2 >>= BOX_C_LOG;
- ;
- ; /* Compute true coordinates of update box's origin corner.
- ; * Actually we compute the coordinates of the center of the corner
- ; * histogram cell, which are the lower bounds of the volume we care about.
- ; */
- ;
- mov ax,word ptr [bp+6]
- shl ax,5
- inc ax
- inc ax
- mov word ptr [bp-2],ax
- ;
- ; minc0 = (c0 << BOX_Y_SHIFT) + ((1 << Y_SHIFT) >> 1);
- ;
- mov ax,word ptr [bp+8]
- shl ax,5
- add ax,4
- mov word ptr [bp-4],ax
- ;
- ; minc1 = (c1 << BOX_C_SHIFT) + ((1 << C_SHIFT) >> 1);
- ;
- mov ax,word ptr [bp+10]
- shl ax,5
- add ax,4
- mov word ptr [bp-6],ax
- ;
- ; minc2 = (c2 << BOX_C_SHIFT) + ((1 << C_SHIFT) >> 1);
- ;
- ; /* Determine which colormap entries are close enough to be candidates
- ; * for the nearest entry to some cell in the update box.
- ; */
- ;
- lea ax,word ptr [bp-272]
- push ax
- push word ptr [bp-6]
- push word ptr [bp-4]
- push word ptr [bp-2]
- push word ptr [bp+4]
- call near ptr find_nearby_colors
- add sp,10
- mov word ptr [bp-16],ax
- ;
- ; numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
- ;
- ; /* Determine the actually nearest colors. */
- ;
- ;
- ; find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
- ;
- lea ax,word ptr [bp-400]
- push ax
- lea ax,word ptr [bp-272]
- push ax
- push word ptr [bp-16]
- push word ptr [bp-6]
- push word ptr [bp-4]
- push word ptr [bp-2]
- push word ptr [bp+4]
- call near ptr find_best_colors
- add sp,14
- ;
- ; bestcolor);
- ;
- ; /* Save the best color numbers (plus 1) in the main cache array */
- ;
- shl word ptr [bp+6],3
- ;
- ; c0 <<= BOX_Y_LOG; /* convert ID back to base cell indexes */
- ;
- shl word ptr [bp+8],2
- ;
- ; c1 <<= BOX_C_LOG;
- ;
- shl word ptr [bp+10],2
- ;
- ; c2 <<= BOX_C_LOG;
- ;
- lea ax,word ptr [bp-400]
- mov si,ax
- ;
- ; cptr = bestcolor;
- ;
- mov word ptr [bp-8],0
- jmp short @11@242
- @11@50:
- ;
- ; for (ic0 = 0; ic0 < BOX_Y_ELEMS; ic0++) {
- ;
- mov word ptr [bp-10],0
- jmp short @11@194
- @11@74:
- ;
- ; for (ic1 = 0; ic1 < BOX_C_ELEMS; ic1++) {
- ;
- mov ax,word ptr [bp+6]
- add ax,word ptr [bp-8]
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,word ptr [bp+8]
- add bx,word ptr [bp-10]
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp+10]
- shl bx,1
- add dx,bx
- mov word ptr [bp-12],ax
- mov word ptr [bp-14],dx
- ;
- ; cachep = & histogram[c0+ic0][c1+ic1][c2];
- ;
- xor di,di
- jmp short @11@146
- @11@98:
- ;
- ; for (ic2 = 0; ic2 < BOX_C_ELEMS; ic2++) {
- ;
- mov al,byte ptr [si]
- mov ah,0
- inc ax
- les bx,dword ptr [bp-14]
- mov word ptr es:[bx],ax
- inc si
- add word ptr [bp-14],2
- inc di
- @11@146:
- cmp di,4
- jl short @11@98
- inc word ptr [bp-10]
- @11@194:
- cmp word ptr [bp-10],4
- jl short @11@74
- inc word ptr [bp-8]
- @11@242:
- cmp word ptr [bp-8],8
- jl short @11@50
- ;
- ; *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
- ; }
- ; }
- ; }
- ;
- pop di
- pop si
- leave
- ret
- fill_inverse_cmap endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- pass2_nodither proc near
- push bp
- mov bp,sp
- sub sp,32
- push si
- push di
- ;
- ; pass2_nodither (decompress_info_ptr cinfo, int num_rows,
- ; JSAMPIMAGE image_data, JSAMPARRAY output_workspace)
- ; /* This version performs no dithering */
- ; {
- ; register JSAMPROW ptr0, ptr1, ptr2, outptr;
- ; register histptr cachep;
- ; register int c0, c1, c2;
- ; int row;
- ; long col;
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx+38]
- mov dx,word ptr [bx+36]
- mov word ptr [bp-30],ax
- mov word ptr [bp-32],dx
- ;
- ; long width = cinfo->image_width;
- ;
- ; /* Convert data to colormap indexes, which we save in output_workspace */
- ;
- mov word ptr [bp-24],0
- jmp @12@266
- @12@50:
- ;
- ; for (row = 0; row < num_rows; row++) {
- ;
- mov ax,word ptr [bp-24]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; ptr0 = image_data[0][row];
- ;
- mov ax,word ptr [bp-24]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+2]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-6],ax
- mov word ptr [bp-8],dx
- ;
- ; ptr1 = image_data[1][row];
- ;
- mov ax,word ptr [bp-24]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+4]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-10],ax
- mov word ptr [bp-12],dx
- ;
- ; ptr2 = image_data[2][row];
- ;
- mov ax,word ptr [bp-24]
- shl ax,2
- mov bx,word ptr [bp+10]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-14],ax
- mov word ptr [bp-16],dx
- ;
- ; outptr = output_workspace[row];
- ;
- mov ax,word ptr [bp-30]
- mov dx,word ptr [bp-32]
- mov word ptr [bp-26],ax
- mov word ptr [bp-28],dx
- jmp @12@170
- @12@74:
- ;
- ; for (col = width; col > 0; col--) {
- ; /* get pixel value and index into the cache */
- ;
- les bx,dword ptr [bp-4]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,2
- mov si,ax
- inc word ptr [bp-4]
- ;
- ; c0 = GETJSAMPLE(*ptr0++) >> Y_SHIFT;
- ;
- les bx,dword ptr [bp-8]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,3
- mov di,ax
- inc word ptr [bp-8]
- ;
- ; c1 = GETJSAMPLE(*ptr1++) >> C_SHIFT;
- ;
- les bx,dword ptr [bp-12]
- mov al,byte ptr es:[bx]
- mov ah,0
- sar ax,3
- mov word ptr [bp-22],ax
- inc word ptr [bp-12]
- ;
- ; c2 = GETJSAMPLE(*ptr2++) >> C_SHIFT;
- ;
- mov ax,si
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,di
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-22]
- shl bx,1
- add dx,bx
- mov word ptr [bp-18],ax
- mov word ptr [bp-20],dx
- ;
- ; cachep = & histogram[c0][c1][c2];
- ; /* If we have not seen this color before, find nearest colormap entry */
- ; /* and update the cache */
- ;
- les bx,dword ptr [bp-20]
- cmp word ptr es:[bx],0
- jne short @12@122
- ;
- ; if (*cachep == 0)
- ;
- push word ptr [bp-22]
- push di
- push si
- push word ptr [bp+4]
- call near ptr fill_inverse_cmap
- add sp,8
- @12@122:
- ;
- ; fill_inverse_cmap(cinfo, c0,c1,c2);
- ; /* Now emit the colormap index for this cell */
- ;
- les bx,dword ptr [bp-20]
- mov al,byte ptr es:[bx]
- dec al
- les bx,dword ptr [bp-16]
- mov byte ptr es:[bx],al
- inc word ptr [bp-16]
- sub word ptr [bp-28],1
- sbb word ptr [bp-26],0
- @12@170:
- cmp word ptr [bp-26],0
- jle @@10
- jmp @12@74
- @@10:
- jne short @12@242
- cmp word ptr [bp-28],0
- jbe @@11
- jmp @12@74
- @@11:
- @12@242:
- inc word ptr [bp-24]
- @12@266:
- mov ax,word ptr [bp-24]
- cmp ax,word ptr [bp+6]
- jge @@12
- jmp @12@50
- @@12:
- ;
- ; *outptr++ = (JSAMPLE) (*cachep - 1);
- ; }
- ; }
- ; /* Emit converted rows to the output file */
- ;
- lea ax,word ptr [bp+10]
- push ax
- push word ptr [bp+6]
- push word ptr [bp+4]
- mov bx,word ptr [bp+4]
- mov bx,word ptr [bx]
- call word ptr [bx+62]
- add sp,6
- ;
- ; (*cinfo->methods->put_pixel_rows) (cinfo, num_rows, &output_workspace);
- ;
- pop di
- pop si
- leave
- ret
- pass2_nodither endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- pass2_dither proc near
- push bp
- mov bp,sp
- sub sp,46
- push si
- push di
- ;
- ; pass2_dither (decompress_info_ptr cinfo, int num_rows,
- ; JSAMPIMAGE image_data, JSAMPARRAY output_workspace)
- ; /* This version performs Floyd-Steinberg dithering */
- ; {
- ; register FSERROR val;
- ; register FSERRPTR thisrowerr, nextrowerr;
- ; register FSERROR c0, c1, c2;
- ; register int pixcode;
- ; JSAMPROW ptr0, ptr1, ptr2, outptr;
- ; histptr cachep;
- ; int dir;
- ; long col;
- ; int row;
- ;
- mov bx,word ptr [bp+4]
- mov ax,word ptr [bx+38]
- mov dx,word ptr [bx+36]
- mov word ptr [bp-44],ax
- mov word ptr [bp-46],dx
- ;
- ; long width = cinfo->image_width;
- ;
- ; /* Convert data to colormap indexes, which we save in output_workspace */
- ;
- mov word ptr [bp-42],0
- jmp @13@626
- @13@50:
- ;
- ; for (row = 0; row < num_rows; row++) {
- ;
- mov ax,word ptr [bp-42]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-16],ax
- mov word ptr [bp-18],dx
- ;
- ; ptr0 = image_data[0][row];
- ;
- mov ax,word ptr [bp-42]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+2]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-20],ax
- mov word ptr [bp-22],dx
- ;
- ; ptr1 = image_data[1][row];
- ;
- mov ax,word ptr [bp-42]
- shl ax,2
- mov bx,word ptr [bp+8]
- mov bx,word ptr [bx+4]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-24],ax
- mov word ptr [bp-26],dx
- ;
- ; ptr2 = image_data[2][row];
- ;
- mov ax,word ptr [bp-42]
- shl ax,2
- mov bx,word ptr [bp+10]
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov word ptr [bp-28],ax
- mov word ptr [bp-30],dx
- ;
- ; outptr = output_workspace[row];
- ;
- cmp word ptr DGROUP:on_odd_row,0
- je short @13@98
- ;
- ; if (on_odd_row) {
- ; /* work right to left in this row */
- ;
- mov ax,word ptr [bp-46]
- dec ax
- add word ptr [bp-18],ax
- ;
- ; ptr0 += width - 1;
- ;
- mov ax,word ptr [bp-46]
- dec ax
- add word ptr [bp-22],ax
- ;
- ; ptr1 += width - 1;
- ;
- mov ax,word ptr [bp-46]
- dec ax
- add word ptr [bp-26],ax
- ;
- ; ptr2 += width - 1;
- ;
- mov ax,word ptr [bp-46]
- dec ax
- add word ptr [bp-30],ax
- ;
- ; outptr += width - 1;
- ;
- mov word ptr [bp-36],65535
- ;
- ; dir = -1;
- ;
- mov ax,word ptr DGROUP:oddrowerrs+2
- mov dx,word ptr DGROUP:oddrowerrs
- add dx,6
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; thisrowerr = oddrowerrs + 3;
- ;
- mov cx,word ptr [bp-44]
- mov bx,word ptr [bp-46]
- xor dx,dx
- mov ax,3
- call near ptr N_LXMUL@
- shl ax,1
- mov dx,word ptr DGROUP:evenrowerrs+2
- mov bx,word ptr DGROUP:evenrowerrs
- add bx,ax
- mov word ptr [bp-6],dx
- mov word ptr [bp-8],bx
- ;
- ; nextrowerr = evenrowerrs + width*3;
- ;
- mov word ptr DGROUP:on_odd_row,0
- ;
- ; on_odd_row = FALSE; /* flip for next time */
- ;
- jmp short @13@122
- @13@98:
- ;
- ; } else {
- ; /* work left to right in this row */
- ;
- mov word ptr [bp-36],1
- ;
- ; dir = 1;
- ;
- mov ax,word ptr DGROUP:evenrowerrs+2
- mov dx,word ptr DGROUP:evenrowerrs
- add dx,6
- mov word ptr [bp-2],ax
- mov word ptr [bp-4],dx
- ;
- ; thisrowerr = evenrowerrs + 3;
- ;
- mov cx,word ptr [bp-44]
- mov bx,word ptr [bp-46]
- xor dx,dx
- mov ax,3
- call near ptr N_LXMUL@
- shl ax,1
- mov dx,word ptr DGROUP:oddrowerrs+2
- mov bx,word ptr DGROUP:oddrowerrs
- add bx,ax
- mov word ptr [bp-6],dx
- mov word ptr [bp-8],bx
- ;
- ; nextrowerr = oddrowerrs + width*3;
- ;
- mov word ptr DGROUP:on_odd_row,1
- @13@122:
- ;
- ; on_odd_row = TRUE; /* flip for next time */
- ; }
- ; /* need only initialize this one entry in nextrowerr */
- ;
- les bx,dword ptr [bp-8]
- xor ax,ax
- mov word ptr es:[bx+4],ax
- mov word ptr es:[bx+2],ax
- mov word ptr es:[bx],ax
- ;
- ; nextrowerr[0] = nextrowerr[1] = nextrowerr[2] = 0;
- ;
- mov ax,word ptr [bp-44]
- mov dx,word ptr [bp-46]
- mov word ptr [bp-38],ax
- mov word ptr [bp-40],dx
- jmp @13@530
- @13@146:
- ;
- ; for (col = width; col > 0; col--) {
- ; /* Get this pixel's value and add accumulated errors */
- ; /* The errors are in units of 1/16th pixel value */
- ;
- les bx,dword ptr [bp-18]
- mov al,byte ptr es:[bx]
- mov ah,0
- shl ax,4
- les bx,dword ptr [bp-4]
- add ax,word ptr es:[bx]
- mov si,ax
- ;
- ; val = (GETJSAMPLE(*ptr0) << 4) + thisrowerr[0];
- ;
- or si,si
- jg short @13@194
- xor si,si
- jmp short @13@242
- @13@194:
- ;
- ; if (val <= 0) val = 0; /* must watch for range overflow! */
- ; else {
- ;
- add si,8
- ;
- ; val += 8; /* divide by 16 with proper rounding */
- ;
- sar si,4
- ;
- ; val >>= 4;
- ;
- cmp si,255
- jle short @13@242
- mov si,255
- @13@242:
- ;
- ; if (val > MAXJSAMPLE) val = MAXJSAMPLE;
- ; }
- ;
- mov di,si
- ;
- ; c0 = val;
- ;
- les bx,dword ptr [bp-22]
- mov al,byte ptr es:[bx]
- mov ah,0
- shl ax,4
- les bx,dword ptr [bp-4]
- add ax,word ptr es:[bx+2]
- mov si,ax
- ;
- ; val = (GETJSAMPLE(*ptr1) << 4) + thisrowerr[1];
- ;
- or si,si
- jg short @13@290
- xor si,si
- jmp short @13@338
- @13@290:
- ;
- ; if (val <= 0) val = 0; /* must watch for range overflow! */
- ; else {
- ;
- add si,8
- ;
- ; val += 8; /* divide by 16 with proper rounding */
- ;
- sar si,4
- ;
- ; val >>= 4;
- ;
- cmp si,255
- jle short @13@338
- mov si,255
- @13@338:
- ;
- ; if (val > MAXJSAMPLE) val = MAXJSAMPLE;
- ; }
- ;
- mov word ptr [bp-10],si
- ;
- ; c1 = val;
- ;
- les bx,dword ptr [bp-26]
- mov al,byte ptr es:[bx]
- mov ah,0
- shl ax,4
- les bx,dword ptr [bp-4]
- add ax,word ptr es:[bx+4]
- mov si,ax
- ;
- ; val = (GETJSAMPLE(*ptr2) << 4) + thisrowerr[2];
- ;
- or si,si
- jg short @13@386
- xor si,si
- jmp short @13@434
- @13@386:
- ;
- ; if (val <= 0) val = 0; /* must watch for range overflow! */
- ; else {
- ;
- add si,8
- ;
- ; val += 8; /* divide by 16 with proper rounding */
- ;
- sar si,4
- ;
- ; val >>= 4;
- ;
- cmp si,255
- jle short @13@434
- mov si,255
- @13@434:
- ;
- ; if (val > MAXJSAMPLE) val = MAXJSAMPLE;
- ; }
- ;
- mov word ptr [bp-12],si
- ;
- ; c2 = val;
- ; /* Index into the cache with adjusted value */
- ;
- mov ax,di
- sar ax,2
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- mov ax,word ptr [bx+2]
- mov dx,word ptr [bx]
- mov bx,word ptr [bp-10]
- sar bx,3
- shl bx,6
- add dx,bx
- mov bx,word ptr [bp-12]
- sar bx,3
- shl bx,1
- add dx,bx
- mov word ptr [bp-32],ax
- mov word ptr [bp-34],dx
- ;
- ; cachep = & histogram[c0 >> Y_SHIFT][c1 >> C_SHIFT][c2 >> C_SHIFT];
- ; /* If we have not seen this color before, find nearest colormap */
- ; /* entry and update the cache */
- ;
- les bx,dword ptr [bp-34]
- cmp word ptr es:[bx],0
- jne short @13@482
- ;
- ; if (*cachep == 0)
- ;
- mov ax,word ptr [bp-12]
- sar ax,3
- push ax
- mov ax,word ptr [bp-10]
- sar ax,3
- push ax
- mov ax,di
- sar ax,2
- push ax
- push word ptr [bp+4]
- call near ptr fill_inverse_cmap
- add sp,8
- @13@482:
- ;
- ; fill_inverse_cmap(cinfo, c0 >> Y_SHIFT, c1 >> C_SHIFT, c2 >> C_SHIFT);
- ; /* Now emit the colormap index for this cell */
- ;
- les bx,dword ptr [bp-34]
- mov ax,word ptr es:[bx]
- dec ax
- mov word ptr [bp-14],ax
- ;
- ; pixcode = *cachep - 1;
- ;
- les bx,dword ptr [bp-30]
- mov al,byte ptr [bp-14]
- mov byte ptr es:[bx],al
- ;
- ; *outptr = (JSAMPLE) pixcode;
- ; /* Compute representation error for this pixel */
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx]
- add bx,word ptr [bp-14]
- mov al,byte ptr es:[bx]
- mov ah,0
- sub di,ax
- ;
- ; c0 -= (FSERROR) GETJSAMPLE(my_colormap[0][pixcode]);
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+4]
- add bx,word ptr [bp-14]
- mov al,byte ptr es:[bx]
- mov ah,0
- sub word ptr [bp-10],ax
- ;
- ; c1 -= (FSERROR) GETJSAMPLE(my_colormap[1][pixcode]);
- ;
- mov bx,word ptr DGROUP:my_colormap
- les bx,dword ptr [bx+8]
- add bx,word ptr [bp-14]
- mov al,byte ptr es:[bx]
- mov ah,0
- sub word ptr [bp-12],ax
- ;
- ; c2 -= (FSERROR) GETJSAMPLE(my_colormap[2][pixcode]);
- ; /* Propagate error to adjacent pixels */
- ; /* Remember that nextrowerr entries are in reverse order! */
- ;
- mov ax,di
- shl ax,1
- mov si,ax
- ;
- ; val = c0 * 2;
- ;
- les bx,dword ptr [bp-8]
- mov word ptr es:[bx-6],di
- ;
- ; nextrowerr[0-3] = c0; /* not +=, since not initialized yet */
- ;
- add di,si
- ;
- ; c0 += val; /* form error * 3 */
- ;
- add word ptr es:[bx+6],di
- ;
- ; nextrowerr[0+3] += c0;
- ;
- add di,si
- ;
- ; c0 += val; /* form error * 5 */
- ;
- add word ptr es:[bx],di
- ;
- ; nextrowerr[0 ] += c0;
- ;
- add di,si
- ;
- ; c0 += val; /* form error * 7 */
- ;
- les bx,dword ptr [bp-4]
- add word ptr es:[bx+6],di
- ;
- ; thisrowerr[0+3] += c0;
- ;
- mov ax,word ptr [bp-10]
- shl ax,1
- mov si,ax
- ;
- ; val = c1 * 2;
- ;
- les bx,dword ptr [bp-8]
- mov ax,word ptr [bp-10]
- mov word ptr es:[bx-4],ax
- ;
- ; nextrowerr[1-3] = c1; /* not +=, since not initialized yet */
- ;
- add word ptr [bp-10],si
- ;
- ; c1 += val; /* form error * 3 */
- ;
- mov ax,word ptr [bp-10]
- add word ptr es:[bx+8],ax
- ;
- ; nextrowerr[1+3] += c1;
- ;
- add word ptr [bp-10],si
- ;
- ; c1 += val; /* form error * 5 */
- ;
- mov ax,word ptr [bp-10]
- add word ptr es:[bx+2],ax
- ;
- ; nextrowerr[1 ] += c1;
- ;
- add word ptr [bp-10],si
- ;
- ; c1 += val; /* form error * 7 */
- ;
- les bx,dword ptr [bp-4]
- mov ax,word ptr [bp-10]
- add word ptr es:[bx+8],ax
- ;
- ; thisrowerr[1+3] += c1;
- ;
- mov ax,word ptr [bp-12]
- shl ax,1
- mov si,ax
- ;
- ; val = c2 * 2;
- ;
- les bx,dword ptr [bp-8]
- mov ax,word ptr [bp-12]
- mov word ptr es:[bx-2],ax
- ;
- ; nextrowerr[2-3] = c2; /* not +=, since not initialized yet */
- ;
- add word ptr [bp-12],si
- ;
- ; c2 += val; /* form error * 3 */
- ;
- mov ax,word ptr [bp-12]
- add word ptr es:[bx+10],ax
- ;
- ; nextrowerr[2+3] += c2;
- ;
- add word ptr [bp-12],si
- ;
- ; c2 += val; /* form error * 5 */
- ;
- mov ax,word ptr [bp-12]
- add word ptr es:[bx+4],ax
- ;
- ; nextrowerr[2 ] += c2;
- ;
- add word ptr [bp-12],si
- ;
- ; c2 += val; /* form error * 7 */
- ;
- les bx,dword ptr [bp-4]
- mov ax,word ptr [bp-12]
- add word ptr es:[bx+10],ax
- ;
- ; thisrowerr[2+3] += c2;
- ; /* Advance to next column */
- ;
- mov ax,word ptr [bp-36]
- add word ptr [bp-18],ax
- ;
- ; ptr0 += dir;
- ;
- add word ptr [bp-22],ax
- ;
- ; ptr1 += dir;
- ;
- add word ptr [bp-26],ax
- ;
- ; ptr2 += dir;
- ;
- add word ptr [bp-30],ax
- ;
- ; outptr += dir;
- ;
- add word ptr [bp-4],6
- ;
- ; thisrowerr += 3; /* cur-row error ptr advances to right */
- ;
- sub word ptr [bp-8],6
- sub word ptr [bp-40],1
- sbb word ptr [bp-38],0
- @13@530:
- cmp word ptr [bp-38],0
- jle @@13
- jmp @13@146
- @@13:
- jne short @13@602
- cmp word ptr [bp-40],0
- jbe @@14
- jmp @13@146
- @@14:
- @13@602:
- inc word ptr [bp-42]
- @13@626:
- mov ax,word ptr [bp-42]
- cmp ax,word ptr [bp+6]
- jge @@15
- jmp @13@50
- @@15:
- ;
- ; nextrowerr -= 3; /* next-row error ptr advances to left */
- ; }
- ; }
- ; /* Emit converted rows to the output file */
- ;
- lea ax,word ptr [bp+10]
- push ax
- push word ptr [bp+6]
- push word ptr [bp+4]
- mov bx,word ptr [bp+4]
- mov bx,word ptr [bx]
- call word ptr [bx+62]
- add sp,6
- ;
- ; (*cinfo->methods->put_pixel_rows) (cinfo, num_rows, &output_workspace);
- ;
- pop di
- pop si
- leave
- ret
- pass2_dither endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- color_quant_init proc near
- push bp
- mov bp,sp
- dec sp
- dec sp
- push si
- push di
- mov si,word ptr [bp+4]
- ;
- ; color_quant_init (decompress_info_ptr cinfo)
- ; {
- ; int i;
- ;
- ; /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
- ;
- cmp word ptr [si+24],8
- jge short @14@74
- ;
- ; if (cinfo->desired_number_of_colors < 8)
- ;
- push offset DGROUP:s@+36
- mov bx,word ptr [si+2]
- call word ptr [bx]
- inc sp
- inc sp
- @14@74:
- ;
- ; ERREXIT(cinfo->emethods, "Cannot request less than 8 quantized colors");
- ; /* Make sure colormap indexes can be represented by JSAMPLEs */
- ;
- cmp word ptr [si+24],256
- jle short @14@122
- ;
- ; if (cinfo->desired_number_of_colors > MAXNUMCOLORS)
- ; ERREXIT1(cinfo->emethods, "Cannot request more than %d quantized colors",
- ;
- mov bx,word ptr [si+2]
- mov word ptr [bx+6],256
- push offset DGROUP:s@+80
- mov bx,word ptr [si+2]
- call word ptr [bx]
- inc sp
- inc sp
- @14@122:
- ;
- ; MAXNUMCOLORS);
- ;
- ; /* Allocate and zero the histogram */
- ;
- ;
- ; histogram = (hist3d) (*cinfo->emethods->alloc_small)
- ;
- push 256
- mov bx,word ptr [si+2]
- call word ptr [bx+22]
- inc sp
- inc sp
- mov word ptr DGROUP:histogram,ax
- ;
- ; (HIST_Y_ELEMS * SIZEOF(hist2d));
- ;
- xor di,di
- jmp short @14@194
- @14@146:
- ;
- ; for (i = 0; i < HIST_Y_ELEMS; i++) {
- ;
- ;
- ; histogram[i] = (hist2d) (*cinfo->emethods->alloc_medium)
- ;
- push 2048
- mov bx,word ptr [si+2]
- call word ptr [bx+26]
- inc sp
- inc sp
- mov bx,di
- shl bx,2
- push ax
- push dx
- push bx
- mov bx,word ptr DGROUP:histogram
- pop ax
- add bx,ax
- pop ax
- mov word ptr [bx+2],ax
- pop ax
- mov word ptr [bx],ax
- ;
- ; (HIST_C_ELEMS*HIST_C_ELEMS * SIZEOF(histcell));
- ;
- ;
- ; jzero_far((void FAR *) histogram[i],
- ;
- push 2048
- mov ax,di
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- push word ptr [bx+2]
- push word ptr [bx]
- call near ptr _jzero_far
- add sp,6
- inc di
- @14@194:
- cmp di,64
- jl short @14@146
- ;
- ; HIST_C_ELEMS*HIST_C_ELEMS * SIZEOF(histcell));
- ; }
- ;
- ; /* Allocate storage for the internal and external colormaps. */
- ; /* We do this now since it is FAR storage and may affect the memory */
- ; /* manager's space calculations. */
- ;
- ;
- ; my_colormap = (*cinfo->emethods->alloc_small_sarray)
- ; ((long) cinfo->desired_number_of_colors,
- ;
- push 0
- push 3
- mov ax,word ptr [si+24]
- cwd
- push dx
- push ax
- mov bx,word ptr [si+2]
- call word ptr [bx+30]
- add sp,8
- mov word ptr DGROUP:my_colormap,ax
- ;
- ; (long) 3);
- ;
- ;
- ; cinfo->colormap = (*cinfo->emethods->alloc_small_sarray)
- ; ((long) cinfo->desired_number_of_colors,
- ;
- mov ax,word ptr [si+139]
- cwd
- push dx
- push ax
- mov ax,word ptr [si+24]
- cwd
- push dx
- push ax
- mov bx,word ptr [si+2]
- call word ptr [bx+30]
- add sp,8
- mov word ptr [si+145],ax
- ;
- ; (long) cinfo->color_out_comps);
- ;
- ; /* Allocate Floyd-Steinberg workspace if necessary */
- ; /* This isn't needed until pass 2, but again it is FAR storage. */
- ;
- cmp word ptr [si+22],0
- je short @14@266
- ;
- ; if (cinfo->use_dithering) {
- ;
- mov cx,word ptr [si+38]
- mov bx,word ptr [si+36]
- add bx,2
- adc cx,0
- xor dx,dx
- mov ax,6
- call near ptr N_LXMUL@
- mov word ptr [bp-2],ax
- ;
- ; size_t arraysize = (size_t) ((cinfo->image_width + 2L) * 3L * SIZEOF(FSERROR));
- ;
- ;
- push word ptr [bp-2]
- mov bx,word ptr [si+2]
- call word ptr [bx+26]
- inc sp
- inc sp
- mov word ptr DGROUP:evenrowerrs+2,dx
- mov word ptr DGROUP:evenrowerrs,ax
- ;
- ; evenrowerrs = (FSERRPTR) (*cinfo->emethods->alloc_medium) (arraysize);
- ;
- push word ptr [bp-2]
- mov bx,word ptr [si+2]
- call word ptr [bx+26]
- inc sp
- inc sp
- mov word ptr DGROUP:oddrowerrs+2,dx
- mov word ptr DGROUP:oddrowerrs,ax
- ;
- ; oddrowerrs = (FSERRPTR) (*cinfo->emethods->alloc_medium) (arraysize);
- ; /* we only need to zero the forward contribution for current row. */
- ;
- push word ptr [bp-2]
- push word ptr DGROUP:evenrowerrs+2
- push word ptr DGROUP:evenrowerrs
- call near ptr _jzero_far
- add sp,6
- ;
- ; jzero_far((void FAR *) evenrowerrs, arraysize);
- ;
- mov word ptr DGROUP:on_odd_row,0
- @14@266:
- ;
- ; on_odd_row = FALSE;
- ; }
- ;
- ; /* Indicate number of passes needed, excluding the prescan pass. */
- ;
- inc word ptr [si+147]
- ;
- ; cinfo->total_passes++; /* I always use one pass */
- ;
- pop di
- pop si
- leave
- ret
- color_quant_init endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- color_quant_doit proc near
- push bp
- mov bp,sp
- push si
- push di
- mov si,word ptr [bp+4]
- ;
- ; color_quant_doit (decompress_info_ptr cinfo, quantize_caller_ptr source_method)
- ; {
- ; int i;
- ;
- ; /* Select the representative colors */
- ;
- push si
- call near ptr select_colors
- inc sp
- inc sp
- ;
- ; select_colors(cinfo);
- ; /* Pass the external colormap to the output module. */
- ; /* NB: the output module may continue to use the colormap until shutdown. */
- ;
- ;
- ; (*cinfo->methods->put_color_map) (cinfo, cinfo->actual_number_of_colors,
- ;
- push word ptr [si+145]
- push word ptr [si+143]
- push si
- mov bx,word ptr [si]
- call word ptr [bx+60]
- add sp,6
- ;
- ; cinfo->colormap);
- ; /* Re-zero the histogram so pass 2 can use it as nearest-color cache */
- ;
- xor di,di
- jmp short @15@98
- @15@50:
- ;
- ; for (i = 0; i < HIST_Y_ELEMS; i++) {
- ;
- ;
- ; jzero_far((void FAR *) histogram[i],
- ;
- push 2048
- mov ax,di
- shl ax,2
- mov bx,word ptr DGROUP:histogram
- add bx,ax
- push word ptr [bx+2]
- push word ptr [bx]
- call near ptr _jzero_far
- add sp,6
- inc di
- @15@98:
- cmp di,64
- jl short @15@50
- ;
- ; HIST_C_ELEMS*HIST_C_ELEMS * SIZEOF(histcell));
- ; }
- ; /* Perform pass 2 */
- ;
- cmp word ptr [si+22],0
- je short @15@170
- ;
- ; if (cinfo->use_dithering)
- ;
- push offset pass2_dither
- jmp short @15@194
- @15@170:
- ;
- ; (*source_method) (cinfo, pass2_dither);
- ; else
- ;
- push offset pass2_nodither
- @15@194:
- push si
- call word ptr [bp+6]
- add sp,4
- ;
- ; (*source_method) (cinfo, pass2_nodither);
- ;
- pop di
- pop si
- pop bp
- ret
- color_quant_doit endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- color_quant_term proc near
- push bp
- mov bp,sp
- ;
- ; color_quant_term (decompress_info_ptr cinfo)
- ; {
- ; /* no work (we let free_all release the histogram/cache and colormaps) */
- ; /* Note that we *mustn't* free the external colormap before free_all, */
- ; /* since output module may use it! */
- ;
- pop bp
- ret
- color_quant_term endp
- ;
- ; METHODDEF void
- ;
- assume cs:_TEXT
- color_quantize proc near
- push bp
- mov bp,sp
- push si
- mov si,word ptr [bp+4]
- ;
- ; color_quantize (decompress_info_ptr cinfo, int num_rows,
- ; JSAMPIMAGE input_data, JSAMPARRAY output_data)
- ; {
- ;
- push offset DGROUP:s@+125
- mov bx,word ptr [si+2]
- call word ptr [bx]
- inc sp
- inc sp
- ;
- ; ERREXIT(cinfo->emethods, "Should not get here!");
- ;
- pop si
- pop bp
- ret
- color_quantize endp
- ;
- ; GLOBAL void
- ;
- assume cs:_TEXT
- _jsel2quantize proc near
- push bp
- mov bp,sp
- push si
- mov si,word ptr [bp+4]
- ;
- ; jsel2quantize (decompress_info_ptr cinfo)
- ; {
- ;
- cmp word ptr [si+20],0
- je short @18@146
- ;
- ; if (cinfo->two_pass_quantize) {
- ; /* Make sure jdmaster didn't give me a case I can't handle */
- ;
- cmp word ptr [si+53],3
- jne short @18@98
- cmp word ptr [si+46],3
- je short @18@122
- @18@98:
- ;
- ; if (cinfo->num_components != 3 || cinfo->jpeg_color_space != CS_YCbCr)
- ;
- push offset DGROUP:s@+146
- mov bx,word ptr [si+2]
- call word ptr [bx]
- inc sp
- inc sp
- @18@122:
- ;
- ; ERREXIT(cinfo->emethods, "2-pass quantization only handles YCbCr input");
- ;
- mov bx,word ptr [si]
- mov word ptr [bx+48],offset color_quant_init
- ;
- ; cinfo->methods->color_quant_init = color_quant_init;
- ;
- mov bx,word ptr [si]
- mov word ptr [bx+52],offset color_quant_prescan
- ;
- ; cinfo->methods->color_quant_prescan = color_quant_prescan;
- ;
- mov bx,word ptr [si]
- mov word ptr [bx+54],offset color_quant_doit
- ;
- ; cinfo->methods->color_quant_doit = color_quant_doit;
- ;
- mov bx,word ptr [si]
- mov word ptr [bx+56],offset color_quant_term
- ;
- ; cinfo->methods->color_quant_term = color_quant_term;
- ;
- mov bx,word ptr [si]
- mov word ptr [bx+50],offset color_quantize
- @18@146:
- ;
- ; cinfo->methods->color_quantize = color_quantize;
- ; }
- ;
- pop si
- pop bp
- ret
- _jsel2quantize endp
- _TEXT ends
- _BSS segment word public 'BSS'
- on_odd_row label word
- db 2 dup (?)
- evenrowerrs label dword
- db 4 dup (?)
- boxlist label word
- db 2 dup (?)
- oddrowerrs label dword
- db 4 dup (?)
- numboxes label word
- db 2 dup (?)
- histogram label word
- db 2 dup (?)
- my_colormap label word
- db 2 dup (?)
- _BSS ends
- _DATA segment word public 'DATA'
- s@ label byte
- db 'Selected %d colors for quantization'
- db 0
- db 'Cannot request less than 8 quantized colors'
- db 0
- db 'Cannot request more than %d quantized colors'
- db 0
- db 'Should not get here!'
- db 0
- db '2-pass quantization only handles YCbCr input'
- db 0
- _DATA ends
- _TEXT segment byte public 'CODE'
- _TEXT ends
- extrn _jzero_far:near
- _pass2_dither equ pass2_dither
- _median_cut equ median_cut
- _my_colormap equ my_colormap
- _color_quant_prescan equ color_quant_prescan
- _color_quant_term equ color_quant_term
- _color_quantize equ color_quantize
- _histogram equ histogram
- _color_quant_doit equ color_quant_doit
- _color_quant_init equ color_quant_init
- _numboxes equ numboxes
- _oddrowerrs equ oddrowerrs
- public _jsel2quantize
- _update_box equ update_box
- _find_biggest_color_pop equ find_biggest_color_pop
- _compute_color equ compute_color
- _find_biggest_volume equ find_biggest_volume
- _find_nearby_colors equ find_nearby_colors
- _find_best_colors equ find_best_colors
- extrn N_LDIV@:far
- _boxlist equ boxlist
- _evenrowerrs equ evenrowerrs
- _fill_inverse_cmap equ fill_inverse_cmap
- extrn N_LXMUL@:far
- extrn N_LXLSH@:far
- _on_odd_row equ on_odd_row
- _select_colors equ select_colors
- _pass2_nodither equ pass2_nodither
- _remap_colormap equ remap_colormap
- end
-